﻿using System;
using System.Linq;
using System.Web;
using ESN.Models;


namespace ESN.Helpers
{
    public class DynamicPartial
    {
        public static string GetMenu()
        {
            ESNCoreDbContext core = new ESNCoreDbContext();
            var menu = core.Apps.Where(c => c.AppPublic == true);

            string menuList = "<ul class=\"leftMenuList\">";
            foreach (var item in menu)
            {
                menuList += "<li><a href=\"" + item.AppUrl + "\">" + item.AppName + "</a></li>";
            }
            menuList += "</ul>";

            return menuList;
        }

        public static string GetNotification()
        {
            return "<section class=\"featured\"><div class=\"content-wrapper\"><div id=\"appMess1\">" + System.Configuration.ConfigurationManager.AppSettings["AppMess1"] + "</div><div id=\"appMess2\">" + System.Configuration.ConfigurationManager.AppSettings["AppMess2"] + "</div><div id=\"appMess3\">" + System.Configuration.ConfigurationManager.AppSettings["AppMess3"] + "</div></div></section>";
        }

        public static string GetOnlineInfoScript()
        {
            ESNCoreDbContext core = new ESNCoreDbContext();
            Guid id = new Guid();

            if (PermissionHelper.IsAuthenticated(ref id))
            {
                var User = core.Profiles.Find(id);
                var script = "<script type=\"text/javascript\">";
                script += "var YourId = '" + HttpUtility.HtmlEncode(User.UserId) +"';";
                script += "var YourUserName = '" + HttpUtility.HtmlEncode(User.UserName) + "';";
                script += "var YourDisplayName = '" + HttpUtility.HtmlEncode(User.DisplayName) + "';";
                script += "var YourAvatar = '" + HttpUtility.HtmlEncode(User.Avatar) + "';";
                script += "</script>";

                return script;
            }
            else
            {
                return "";
            }
        }
    }
}